gusucode.com > VC++视频目标检测演示帧间差分法-源码程序 > VC++视频目标检测演示帧间差分法-源码程序/code/Video Demo/GravityTrack.cpp
//Download by http://www.NewXing.com #include "StdAfx.h" #include "GravityTrack.h" /******************************************************/ /* 函数名称: /* GravityTrack /* /* 函数参数: /* unsigned char* sGray-输入灰度图像 /* int sWidth-图像宽度 /* int sHeight-图像高度 /* int sThreshold-目标域值 /* /* 说明: /* 形心法目标跟踪程序 /*******************************************************/ /*WININFO GravityTrack (unsigned char* sGray, int sWidth, int sHeight, int sThreshold) { WININFO win; win.w = 0; win.h = 0; win.pt.x = 0; win.pt.y = 0; win.flag = FALSE; int M00bh = 0; int M01bh = 0; int M10bh = 0; int iLine,i,j; for(j=EDGE_SPACE;j<sHeight-EDGE_SPACE;j++) { iLine = 0; for(i=EDGE_SPACE;i<sWidth-EDGE_SPACE;i++) { int k = sWidth*j+i; if(sGray[k]>sThreshold) { iLine++; M01bh+=i; M10bh+=j; } } M00bh+=iLine; if(win.w<iLine) win.w = iLine; if(iLine>0) win.h++; } //if(M00bh>10) //{ win.pt.x = int(M01bh/M00bh+0.5); win.pt.y = int(M10bh/M00bh+0.5); win.w = win.w/2+EDGE_DRAW; win.h = win.h/2+EDGE_DRAW; //win.flag = TRUE; //} return win; } */